#!/usr/bin/perl
use strict;
use warnings;

use lib '../lib';
use ChessLike::Game;

use Test::More 'no_plan';

my $game = ChessLike::Game->new();

is( ref $game, 'ChessLike::Game', '[ref] ChessLike::Game' );

my $game2 = ChessLike::Game->new();
ok( $game->uuid() ne $game2->uuid(), '[uuid] uniqueness' );

is( $game->title, 'New Game', '[new] title: default' );
$game->configure( 'title' => 'Boss Battle!' );
is( $game->title, 'Boss Battle!', '[configure] title' );

is( $game->player( 1 ), 'Player1', '[new] player-1: default' );
is( $game->player( 2 ), 'Player2', '[new] player-2: default' );
is( $game->player( 3 ), undef,     '[new] player-3: sanity' );
is( $game->email_for_player( 0 ), undef, '[new] email-1: default' );
is( $game->email_for_player( 1 ), undef, '[new] email-2: default' );

$game->configure(
   'player-1' => 'Moggo',
   'player-2' => 'Jema',
   'email-1' => 'moggo@ilovepawns.ca',
   'email-2' => 'jema@iloveknights.ca',
   );
is( $game->player( 1 ), 'Moggo', '[configure] player-1' );
is( $game->player( 2 ), 'Jema', '[configure] player-2' );
is( $game->email_for_player( 1 ), 'moggo@ilovepawns.ca', '[configure] email-1' );
is( $game->email_for_player( 2 ), 'jema@iloveknights.ca', '[configure] email-2' );

$game = ChessLike::Game->new(
   'title'   => 'My Game',
   'player-1' => 'Biggs',
   'player-2' => 'Wedge',
   'email-1'  => 'biggs@empire.com',
   'email-2'  => 'wedge@empire.com',
   );

is( $game->title(), 'My Game', '[new] title: custom' );
is( $game->player( 1 ), 'Biggs',   '[new] player-1: custom' );
is( $game->player( 2 ), 'Wedge',   '[new] player-2: custom' );
is( $game->email_for_player( 1 ), 'biggs@empire.com', '[new] email-1: custom' );
is( $game->email_for_player( 2 ), 'wedge@empire.com', '[new] email-2: custom' );

my @actions;
@actions = $game->actions();
is( @actions, 0, '[actions] default' );
$game->add_action( "b5-c3" );
$game->add_action( "h1+a2>s/e3,f4.1" );
$game->add_action( "b7.1*e7.1" );
is( ref $game->actions(), 'ARRAY', '[actions] scalar context' );
@actions = $game->actions();
is( @actions, 3, '[actions] length' );
is( $actions[0], "b5-c3", '[add_action] index 0' );
is( $actions[1], "h1+a2>s/e3,f4.1", '[add_action] index 1' );
is( $actions[2], "b7.1*e7.1", '[add_action] index 2' );

is( $game->current_player(), 1, '[current-player] default' );
is( $game->I_am_player(),    1, '[I-am-player] default' );
$game->next_turn();
is( $game->current_player(), 2, '[current-player] next turn 1' );
is( $game->I_am_player(),    1, '[I-am-player] sanity' );
$game->next_turn();
is( $game->current_player(), 1, '[current-player] next turn 2' );



